//
//  YiJianFanKuiViewController.m
//  XiangMu
//
//  Created by 康世标 on 15/8/12.
//  Copyright (c) 2015年 康世标. All rights reserved.
//

#import "YiJianFanKuiViewController.h"

@interface YiJianFanKuiViewController ()

@end

@implementation YiJianFanKuiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.tabBarController.tabBar.hidden=YES;
    [self.textView.layer setMasksToBounds:YES];
    [self.textView.layer setBorderWidth:.5];
    self.title = @"意见反馈";
    UIButton *fanHuiBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    fanHuiBtn.frame=CGRectMake(20, 20, 10, 20);
    
    [fanHuiBtn setBackgroundImage:[UIImage imageNamed:@"fanhui"] forState:UIControlStateNormal];
    
    [fanHuiBtn addTarget:self action:@selector(FanHui) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *barFanHui=[[UIBarButtonItem alloc]initWithCustomView:fanHuiBtn];
    self.navigationItem.leftBarButtonItem=barFanHui;

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//返回
-(void)FanHui{
    self.tabBarController.tabBar.hidden=NO;
    [self.navigationController popViewControllerAnimated:YES];
    
}
#pragma  mark ---UITextViewDelegate
- (void)textViewDidChange:(UITextView *)textView{
    
    if (textView.text.length>0)
    {
        self.lable1.text=@"";
    }
    else{
         self.lable1.text=@"请留下你的宝贵意见或建议，我们将努力改进。";
    }
}
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}
- (IBAction)FanKui:(UIButton *)sender{
    
    MBProgressHUD * hud =[MBProgressHUD showHUDAddedTo:self.view animated:YES];
    if ([self.textView.text isEqualToString:@""]||self.textView==nil) {
        
        hud.mode = MBProgressHUDModeText;
        hud.labelText = @"请输入反馈内容";
        hud.removeFromSuperViewOnHide = YES;
        [hud hide:YES afterDelay:1];
        
        return;
        
             
    }
    
   long Id = [[[NSUserDefaults standardUserDefaults]objectForKey:@"ID"] longValue];
    
    [QingQiuShuJu YiJianFanKui:@(Id) advice:self.textView.text   blcok:^(NSDictionary *dic, BOOL isOK) {
        
        if (isOK) {
            
            if ([[dic valueForKey:@"status"] intValue]==200) {
                
                hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]];
                
                
                hud.mode = MBProgressHUDModeCustomView;
                
                hud.labelText = @"发布成功";
                
                [hud show:YES];
                hud.removeFromSuperViewOnHide = YES;
                [hud hide:YES afterDelay:2];
                [self performSelector:@selector(backBar) withObject:self afterDelay:2];
                

            }
            else{
                
                hud.mode = MBProgressHUDModeText;
                hud.labelText = [dic valueForKey:@"msg"];
                hud.removeFromSuperViewOnHide = YES;
                [hud hide:YES afterDelay:2];
                
                
            }
            
            NSLog(@"---%@",dic);
        }
        else{
            hud.mode = MBProgressHUDModeText;
            hud.labelText = @"网络连接错误";
            hud.removeFromSuperViewOnHide = YES;
            [hud hide:YES afterDelay:2];
        }
        
    } ];
    
    
}
- (void)backBar{
    
    
    [self.navigationController popViewControllerAnimated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
